{% extends 'base.html' %}
{% import '_macros.html' as macros %}

{% block js %}
    <script>
        {% if current_user.is_authenticated %}
            $(function () {
                $('.add-tag').click(function () {
                    $('.modal-content').load('{{ url_for('tag.tag_create') }}');
                    $('#myModal').modal('show')
                });

                $('.edit-tag').click(function () {
                    var tag_id = $(this).attr('tag_id');
                    $('.modal-content').load('/tag/edit/' + tag_id);
                    $('#myModal').modal('show')
                });

                $('.delete-tag').click(function () {
                    var tag_id = $(this).attr('tag_id');
                    $('.modal-content').load('/tag/delete/' + tag_id);
                    $('#myModal').modal('show')
                });
            });
        {% endif %}
    </script>
{% endblock %}

{% block right %}
    <div class="col-md-12 page-body">
        <div class="row">
            <div class="sub-title">
                <h2>标签管理</h2>
                <a href="{{ url_for('main.index') }}" title="返回首页"><i class="icon-home"></i></a>
                {% if current_user.is_authenticated %}
                <a href="#" title="新增标签" class="add-tag"><i class="icon-plus"></i></a>
                {% endif %}
            </div>
            <div class="col-md-12 content-page">
                <table class="table table-hover list-table">
                    <tbody>
                    {% for tag in pagination.items %}
                        <tr>
                            <td>
                                <a href="#" >{{ tag.name[:50] }}</a>
                            </td>
                            <td>{{ tag.update_on }}</td>
                            {% if current_user.is_authenticated %}
                                <td>
                                    <a href="#" class="edit-tag" title="编辑" tag_id="{{ tag.id }}">
                                        <i class="icon-pencil"></i>
                                    </a>
                                    {% if not tag.blogs.count() %}
                                        <a href="#" class="delete-tag" title="删除" tag_id="{{ tag.id }}">
                                            <i class="icon-trash"></i>
                                        </a>
                                    {% endif %}
                                </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
                <div class="my-pagination">
                    {{ macros.pagination_widget(pagination, 'tag.tag_list') }}
                </div>
            </div>
        </div>
    </div>
    {{ super() }}
{% endblock %}